﻿//-----------------------------------------------------------------------
// <copyright file="LexStrategy.cs" company="tuliprules.org">
//     Copyright (c) 2010 tuplelister, tuliprules.org.
// </copyright>
// <summary>This is the LexStrategy class.</summary>
//-----------------------------------------------------------------------

namespace Tulip.Engine.ConflictResolution
{
    /// <summary>
    /// Lexicographic conflict resolution strategy.
    /// </summary>
    /// <remarks>
    /// <para>Among productions of the same salience, newly activated productions are placed using the 
    /// OPS5 strategy of the same name. First the recency of the pattern entities that activated 
    /// the production is used to determine where to place the activation. Every fact and 
    /// instance is marked internally with a 'time tag' to indicate its relative recency with 
    /// respect to every other fact and instance in the system. The pattern entities associated 
    /// with each rule activation are sorted in descending order for determining placement. An 
    /// activation with a more recent pattern entities is placed before activations with less 
    /// recent pattern entities. To determine the placement order of two activations, compare 
    /// the sorted time tags of the two activations one by one starting with the largest time 
    /// tags. The comparison should continue until one activation's time tag is greater than the 
    /// other activation's corresponding time tag. The activation with the greater time tag is 
    /// placed before the other activation on the agenda.</para>
    /// <para>If one activation has more pattern entities than the other activation and the compared 
    /// time tags are all identical, then the activation with more time tags is placed before 
    /// the other activation on the agenda. If two activations have the exact same recency, the 
    /// activation with the higher specificity is placed above the activation with the lower 
    /// specificity. Unlike OPS5, the not conditional elements in CLIPS have pseudo time tags 
    /// which are used by the LEX conflict resolution strategy. The time tag of a not CE is 
    /// always less than the time tag of a pattern entity, but greater than the time tag of a 
    /// not CE that was instantiated after the not CE in question.</para> 
    /// <para>Example:  Consider the following scenario:</para>
    /// <para>          The following six activations have been listed in their LEX ordering 
    ///           (where the comma at the end of the activation indicates the presence of a 
    ///           not CE). Note that a fact's time tag is not necessarily the same as it's 
    ///           index (since instances are also assigned time tags), but if one fact's 
    ///           index is greater than another facts's index, then itís time tag is also 
    ///           greater. For this example, assume that the time tags and indices are the 
    ///           same.</para> 
    ///  <para>         rule-6: f-1,f-4
    ///           rule-5: f-1,f-2,f-3,
    ///           rule-1: f-1,f-2,f-3
    ///           rule-2: f-3,f-1
    ///           rule-4: f-1,f-2,
    ///           rule-3: f-2,f-1</para>
    ///  <para>         Shown following are the same activations with the fact indices sorted as 
    ///           they would be by the LEX strategy for comparison.</para> 
    ///  <para>         rule-6: f-4,f-1
    ///           rule-5: f-3,f-2,f-1,
    ///           rule-1: f-3,f-2,f-1
    ///           rule-2: f-3,f-1
    ///           rule-4: f-2,f-1,
    ///           rule-3: f-2,f-1</para>
    /// </remarks>
    public class LexStrategy : ConflictResolutionStrategy
    {
        /// <summary>
        /// Factory method returns a new agenda.
        /// </summary>
        /// <returns>A new agenda.</returns>
        public override Agenda NewAgenda()
        {
            // TODO: return agenda here
            return null;
        }

        /// <summary>
        /// Factory method creates a new agenda list.
        /// </summary>
        /// <returns>A new agenda list.</returns>
        public override IAgendaList CreateAgendaList()
        {
            return null;
        }
    }
}
